﻿using System;
using System.Collections.Generic;

namespace USTF.Media.MediaService
{
    public static class DictionaryHelper
    {
        public static string SafeGetValue(this IDictionary<string, string> data, string key, string defaultValue)
        {
            if (data.ContainsKey(key))
                return data[key] ?? defaultValue;
            else
                return defaultValue;
        }

        public static int SafeGetInt(this IDictionary<string, string> data, string key, int defaultValue)
        {
            string rawValue = data.SafeGetValue(key, String.Empty);
            if (!String.IsNullOrEmpty(rawValue))
            {
                int convertAttemptedOutput;
                if (int.TryParse(rawValue, out convertAttemptedOutput))
                    return convertAttemptedOutput;
            }

            return defaultValue;
                
        }
    }
}
